package cn.wondertek.cms.service.impl;

import java.beans.Transient;
import java.util.List;

import cn.wondertek.cms.mapper.cmsMapper.CmsSysUserRoleMapper;
import cn.wondertek.cms.mapper.cmsMapper.CmsSysUserRoleMenuMapper;
import cn.wondertek.cms.service.ICmsSysUserRoleService;
import cn.wondertek.common.utils.DateUtils;
import cn.wondertek.system.domain.CmsSysUserRoleMenu;
import cn.wondertek.system.domain.vo.GetCSUROrCmsSURM;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.wondertek.system.domain.CmsSysUserRole;
import cn.wondertek.common.core.text.Convert;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2020-06-01
 */
@Service
public class CmsSysUserRoleServiceImpl implements ICmsSysUserRoleService
{
    @Autowired
    private CmsSysUserRoleMapper cmsSysUserRoleMapper;

    @Autowired
    private CmsSysUserRoleMenuMapper cmsSysUserRoleMenuMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param roleId 【请填写功能名称】ID
     * @return 【请填写功能名称】
     */
    @Override
    public CmsSysUserRole selectCmsSysUserRoleById(Long roleId)
    {
        return cmsSysUserRoleMapper.selectCmsSysUserRoleById(roleId);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param cmsSysUserRole 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<CmsSysUserRole> selectCmsSysUserRoleList(CmsSysUserRole cmsSysUserRole)
    {
        return cmsSysUserRoleMapper.selectCmsSysUserRoleList(cmsSysUserRole);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param cmsSysUserRole 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertCmsSysUserRole(CmsSysUserRole cmsSysUserRole)
    {
        cmsSysUserRole.setCreateTime(DateUtils.getNowDate());
        return cmsSysUserRoleMapper.insertCmsSysUserRole(cmsSysUserRole);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param cmsSysUserRole 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateCmsSysUserRole(CmsSysUserRole cmsSysUserRole)
    {
        cmsSysUserRole.setUpdateTime(DateUtils.getNowDate());
        return cmsSysUserRoleMapper.updateCmsSysUserRole(cmsSysUserRole);
    }

    /**
     * 删除【请填写功能名称】对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteCmsSysUserRoleByIds(String ids)
    {
        return cmsSysUserRoleMapper.deleteCmsSysUserRoleByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param roleId 【请填写功能名称】ID
     * @return 结果
     */
    public int deleteCmsSysUserRoleById(Long roleId)
    {
        return cmsSysUserRoleMapper.deleteCmsSysUserRoleById(roleId);
    }

    @Override
    @Transient
    public int inserCmsSysUserRoleOrCmsSysUserRoleMenu(GetCSUROrCmsSURM getCSUROrCmsSURM) {

        //添加用户信息
        cmsSysUserRoleMapper.insertCmsSysUserRole(getCSUROrCmsSURM.getCmsSysUserRole());
        for (CmsSysUserRoleMenu cmsSysUserRoleMenu:
        getCSUROrCmsSURM.getCmsSysUserRolelist()) {
            cmsSysUserRoleMenuMapper.insertCmsSysUserRoleMenu(cmsSysUserRoleMenu);
        }
        return 1;
    }
}
